//
//  RssiView.m
//  CoolMove
//
//  Created by CA on 15/7/2.
//  Copyright (c) 2015年 CA. All rights reserved.
//

#import "RssiView.h"
#import "MyStyleKit.h"

@interface RssiView ()
@property (nonatomic, assign) NSUInteger countOfRssiBarShow;
@end

@implementation RssiView

- (void)setRssiValue:(NSNumber *)rssiValue
{
    NSInteger rssi = [rssiValue integerValue];
    
    if (rssi >= 0) {
        return;
    }
    
    if (rssi > -50) {
        self.countOfRssiBarShow = 5;
    } else if (rssi > -60) {
        self.countOfRssiBarShow = 4;
    } else if (rssi > -70) {
        self.countOfRssiBarShow = 3;
    } else if (rssi > -80) {
        self.countOfRssiBarShow = 2;
    } else {
        self.countOfRssiBarShow = 1;
    }
    
    _rssiValue = rssiValue;
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
    
    NSMutableArray *rssiSwitchs = [@[] mutableCopy];
    for (NSUInteger index = 0; index < 5; index++) {
        if (index < self.countOfRssiBarShow) {
            [rssiSwitchs addObject:@YES];
        } else {
            [rssiSwitchs addObject:@NO];
        }
    }
    
    [MyStyleKit drawRssiViewWithFrame:rect rSSIColor:self.rssiColor visibleRssi5:[rssiSwitchs[4] boolValue] visibleRssi4:[rssiSwitchs[3] boolValue] visibleRssi3:[rssiSwitchs[2] boolValue] visibleRssi2:[rssiSwitchs[1] boolValue] visibleRssi1:[rssiSwitchs[0] boolValue]];
}


@end
